package br.com.channelll.client;

import br.com.channelll.client.bean.LoginRequestBean;
import br.com.channelll.client.bean.LoginResponseBean;

import channelll.simpleRPC.client.RpcCommand;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.IsSerializable;

public class IncluiLogin {
	
	public static void execute(String login) {
		final String loginName = login;
		
		RpcCommand.go("br.com.channelll.server.rpc.bo.IncluiLoginBO",
				new LoginRequestBean(login),
				new AsyncCallback<IsSerializable>() {

					public void onFailure(Throwable caught) {
						//Window.alert(caught.getStackTrace());
						System.out.println("*** erro: " + caught.getMessage());
					}

					public void onSuccess(IsSerializable result) {
						LoginResponseBean myResponseBean = (LoginResponseBean) result;
						if (myResponseBean.isOk) {
							Window.alert("Usuario já existe");
							return;
						}else{
							Window.alert("Usuário adicionado com sucesso: "+ loginName);
						}
					}
				});
	}
}
